local extension = Package("ldcards", Package.CardPack)
extension.extensionName = "brokenroyal"
extension.game_modes_whitelist = {"brokenroyal_mode"}

local ld = require "packages/brokenroyal/util"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
    ["ldcards"] = "裂鼎卡牌包",
    ["#noinstruction"] = "无指令",
  }

local noinstruction = fk.CreateProhibitSkill{
  name = "#noinstruction",
  prohibit_use = function(self, player, card)
    if player:getMark("instruction") == 0 and player:getMark("free_instruction") == 0 and card and card.skillName ~= "boomerang_skill&" and
     card.skillName ~= "bamboojavelin_skill&" and card.skillName ~= "jinglan_skill&" and 
     (card.skillName ~= "nine_segmented_skill&" or card.number ~= 9) then
      return card.name == "br__slash" or card.trueName == "rumble" or card.trueName == "scout" or
      (card.trueName == "grain" and not ld.hasStandbyEquip(player, "camel")) or 
      (card.trueName == "jink" and (not ld.Equipinvoked(player, "squareshield") or not player:hasSkill("#squareshield_skill"))) or 
      (card.name == "shot__slash" and (not ld.Equipinvoked(player, "light_bow") or not player:hasSkill("#light_bow")))
    end
  end,
}

Fk:addSkill(noinstruction)

local slash = Fk:cloneCard("slash")
local SlashSkill = fk.CreateActiveSkill{
  name = "br__slash_skill",
  prompt = "对对手造成1点伤害（你每回合至多使用【杀】和【射】共计一张）",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_use = function(self, room, cardUseEvent)
    local player = room:getPlayerById(cardUseEvent.from)
    if player:getMark("free_instruction") > 0 then
      room:setPlayerMark(player, "free_instruction", 0)
    else
      ld.addinstruction(player, -1)
    end
  end,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })
  end
}

local Slash = fk.CreateBasicCard{
  name = "br__slash",
  skill = SlashSkill,
  is_damage_card = true,
}

extension:addCards{
  Slash:clone(Card.Spade, 5),
  Slash:clone(Card.Spade, 6),
  Slash:clone(Card.Spade, 7),
  Slash:clone(Card.Spade, 8),
  Slash:clone(Card.Spade, 9),
  Slash:clone(Card.Heart, 4),
  Slash:clone(Card.Heart, 5),
  Slash:clone(Card.Club, 4),
  Slash:clone(Card.Club, 5),
  Slash:clone(Card.Club, 6),
  Slash:clone(Card.Club, 7),
  Slash:clone(Card.Club, 8),
  Slash:clone(Card.Club, 9),
  Slash:clone(Card.Club, 10),
  Slash:clone(Card.Diamond, 3),
  Slash:clone(Card.Diamond, 4),
}

local ShotSlashSkill = fk.CreateActiveSkill{
  name = "shot__slash_skill",
  prompt = "对对手造成1点伤害（你每回合至多使用【杀】和【射】共计一张）",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_use = function(self, room, cardUseEvent)
    if cardUseEvent.card.skillName ~= "boomerang_skill&" and cardUseEvent.card.skillName ~= "bamboojavelin_skill&" then
      local player = room:getPlayerById(cardUseEvent.from)
      if player:getMark("free_instruction") > 0 then
        room:setPlayerMark(player, "free_instruction", 0)
      else
        ld.addinstruction(player, -1)
      end
    end
  end,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from  
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })
  end
}

local ShotSlash = fk.CreateBasicCard{
  name = "shot__slash",
  skill = ShotSlashSkill,
  is_damage_card = true,
}

extension:addCards{
  ShotSlash:clone(Card.Spade, 11),
  ShotSlash:clone(Card.Heart, 11),
  ShotSlash:clone(Card.Club, 11),
  ShotSlash:clone(Card.Diamond, 11),
}

Fk:loadTranslationTable{
  ["br__slash"] = "杀",
  [":br__slash"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：对目标角色造成1点伤害。"..
  "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
  ["shot__slash"] = "射",
  [":shot__slash"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：对目标角色造成1点伤害。"..
  "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
}

local jinkSkill = fk.CreateActiveSkill{
  name = "br__jink_skill",
  can_use = Util.FalseFunc,
  on_use = function(self, room, cardUseEvent)
    local player = room:getPlayerById(cardUseEvent.from)
    if not ld.Equipinvoked(player, "squareshield") or not player:hasSkill("#squareshield_skill") then
      ld.addinstruction(player, -1)
    end
  end,
  on_effect = function(self, room, effect)
    if effect.responseToEvent then
      effect.responseToEvent.isCancellOut = true
    end
  end
}

local jink = fk.CreateBasicCard{
  name = "br__jink",
  skill = jinkSkill,
}

  Fk:loadTranslationTable{
    ["br__jink"] = "防",
    [":br__jink"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：【杀】或【射】对你生效前<br/><b>目标</b>：此【杀】或【射】<br/><b>效果</b>：抵消此【杀】或【射】。"..
    "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
    --["#slash-jink-multi"] = "请使用一张【防】抵消此【射】（共需两张）",
  }

  extension:addCards{
    jink:clone(Card.Spade, 2),
    jink:clone(Card.Spade, 10),
    jink:clone(Card.Heart, 6),
    jink:clone(Card.Heart, 7),
    jink:clone(Card.Club, 2),
    jink:clone(Card.Diamond, 5),
    jink:clone(Card.Diamond, 6),
    jink:clone(Card.Diamond, 7),
    jink:clone(Card.Diamond, 8),
  }  

local medicineSkill = fk.CreateActiveSkill{
  name = "medicine_skill",
  prompt = "你增加1点国力",
  mod_target_filter = function(self, to_select)
    return Fk:currentRoom():getPlayerById(to_select):isWounded()
  end,
  can_use = function(self, player, card)
    return player:isWounded() and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, use)
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      use.tos = { { use.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    if target:isWounded() and not target.dead then
      room:recover({
        who = target,
        num = 1,
        card = effect.card,
        recoverBy = player,
        skillName = self.name
      })
    end
  end
}
local medicine = fk.CreateBasicCard{
  name = "br__analeptic",
  skill = medicineSkill,
}

extension:addCards{
  medicine:clone(Card.Heart, 8),
  medicine:clone(Card.Heart, 9),
  medicine:clone(Card.Heart, 10),
  medicine:clone(Card.Diamond, 9),
  medicine:clone(Card.Diamond, 10),
  medicine:clone(Card.Diamond, 12),
}  

  Fk:loadTranslationTable{
    ["br__analeptic"] = "药",
    [":br__analeptic"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：出牌阶段或你国力为0时<br/><b>目标</b>：你<br/><b>效果</b>：你增加1点国力。"..
    "<br/><font color=\"#800020\"><b>消耗指令：0</b></font>",
  }

  local scoutSkill = fk.CreateActiveSkill{
    name = "scout_skill",
    prompt = "你观看对手的手牌，弃置其中一张",
    mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
      local player = Fk:currentRoom():getPlayerById(to_select)
      return user ~= to_select and not player:isKongcheng()
    end,
    target_filter = function(self, to_select, selected, _, card)
      if #selected < self:getMaxTargetNum(Self, card) then
        return self:modTargetFilter(to_select, selected, Self.id, card, true)
      end
    end,
    target_num = 1,
    can_use = function(self, player)
      return player:getMark("instruction") > 0
    end,
    on_use = function(self, room, cardUseEvent)
      ld.addinstruction(room:getPlayerById(cardUseEvent.from), -1)
    end,
    on_effect = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local target = room:getPlayerById(effect.to)
      if target:isKongcheng() then return end
      local id = room:askForCardChosen(player, target, {
        card_data = {{"$Hand", target.player_cards[Player.Hand]}}
      }, self.name)
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    end
  }
  
  local scout = fk.CreateBasicCard{
    name = "scout",
    skill = scoutSkill,
  }
  
  extension:addCards({
    scout:clone(Card.Spade, 3),
    scout:clone(Card.Spade, 4),
    scout:clone(Card.Heart, 3),
    scout:clone(Card.Club, 3),
  })

  Fk:loadTranslationTable{
    ["scout"] = "探",
    ["scout_skill"] = "探",
    [":scout"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你观看其手牌并弃置其中一张牌。"..
    "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
  }

local planTrigger = fk.CreateTriggerSkill{
  name = "#plan_trigger",
  anim_type = "defensive",
  mute = true,
  priority = 8,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    if data.from == player.id or data.to ~= player.id then return false end
    if (player:hasSkill("#whitehorse_skill") or ld.hasStandbyEquip(player, "whitehorse")) and not ld.hasPolicyorTrap(player, "eightdiagrams") then return true end
    for _, id in ipairs(player:getCardIds(Player.Hand)) do
      local card = Fk:getCardById(id)
      if card and card.name == "plan" then
        if not player:prohibitUse(card) and not player:isProhibited(player, card)
        and player:getMark("instruction") < player:getMark("maxinstruction") then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "plan", nil, "#plan-ask", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    use.responseToEvent = data
    room:useCard(use)
  end,
}

Fk:addSkill(planTrigger)

local planSkill = fk.CreateActiveSkill{
  name = "plan_skill",
  prompt = "#plan-ask",
  mod_target_filter = function(self, to_select)
    return true
  end,
  can_use = function(self, player, card)
    return player:getMark("instruction") < player:getMark("maxinstruction") and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, use)
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      use.tos = { { use.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    ld.addinstruction(target, 1)
  end
}
local plan = fk.CreateBasicCard{
  name = "plan",
  skill = planSkill,
}

extension:addCards({
  plan:clone(Card.Spade, 3),
  plan:clone(Card.Spade, 4),
  plan:clone(Card.Heart, 3),
  plan:clone(Card.Club, 3),
})

Fk:loadTranslationTable{
  ["plan"] = "计",
  [":plan"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：出牌阶段或对手使用目标为你的牌生效前<br/><b>目标</b>：你<br/><b>效果</b>：你增加1点指令。"..
  "<br/><font color=\"#800020\"><b>消耗指令：0</b></font>",
  ["#plan-ask"] = "你可以使用【计】，增加1点指令",
}

  local rumbleTrigger = fk.CreateTriggerSkill{
    name = "#rumble_trigger",
    anim_type = "defensive",
    mute = true,
    priority = 1,
    events = {fk.PreCardEffect},
    can_trigger = function(self, event, target, player, data)
      if data.from == player.id then return false end
      if data.card.name == "scout" or data.card.name == "rumble" or (data.card.type == Card.TypeTrick
      and data.card:getMark("@@policy") == 0 and data.card:getMark("disresponsive") == 0) then
        if player:hasSkill("br__qice") then return (player:getHandcardNum() + player:getMark("instruction")) == 4 end
        if player:hasSkill("#superdiagram") and player:getMark("instruction") > 0 and not ld.hasPolicyorTrap(player, "eightdiagrams") then return true end
        for _, id in ipairs(player:getCardIds(Player.Hand)) do
          local card = Fk:getCardById(id)
          if card and card.name == "rumble" then
            if not player:prohibitUse(card) and not player:isProhibited(player, card) then
              return true
            end
          end
        end
      end
      return false
    end,
    on_cost = function(self, event, target, player, data)
      local use = player.room:askForUseCard(player, "rumble", nil, "#rumble-ask:::" .. data.card:toLogString() , true, nil, data)
      if use then
        self.cost_data = use
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      ld.addinstruction(player, -1)
      local use = self.cost_data
      use.toCard = data.card
      use.responseToEvent = data
      room:useCard(use)
    end,
  }
  
  Fk:addSkill(rumbleTrigger)
  
  local rumbleSkill = fk.CreateActiveSkill{
    name = "rumble_skill",
    can_use = Util.FalseFunc,
    on_effect = function(self, room, effect)
      if effect.toCard.name == "rumble" or effect.toCard.name == "borrowarrows" then
        room:setTag("rumble_effected", not room:getTag("rumble_effected"))
      else
        if effect.responseToEvent then
          if room:getTag("rumble_effected") then
            room:setTag("rumble_effected", false)
          else
            for _, p in ipairs(room.alive_players) do
              table.insertIfNeed(effect.responseToEvent.nullifiedTargets, p.id)
            end
          end
        end
      end
    end,
  }
  
  local rumble = fk.CreateBasicCard{
    name = "rumble",
    skill = rumbleSkill,
  }
  
  extension:addCards{
    rumble:clone(Card.Heart, 12),
    rumble:clone(Card.Heart, 13),
    rumble:clone(Card.Club, 12),
    rumble:clone(Card.Club, 13),
  }

  Fk:loadTranslationTable{
    ["rumble"] = "破",
    [":rumble"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：对手使用的【探】、【破】或不为方针的计谋牌生效前<br/><b>目标</b>：此牌<br/><b>效果</b>：抵消此牌的效果。"..
    "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
    ["#rumble-ask"] = "你可以使用【破】抵消 %arg",
  }

local grainTrigger = fk.CreateTriggerSkill{
  name = "#grain_trigger",
  anim_type = "draw",
  mute = true,
  priority = 3,
  events = {fk.EventPhaseStart, fk.AfterCardUseDeclared},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      if player:hasSkill(self.name) and player.phase == Player.Draw and (ld.hasStandbyEquip(player, "camel") or player:getMark("instruction") > 0) then
        for _, id in ipairs(player:getCardIds(Player.Hand)) do
          local card = Fk:getCardById(id)
          if card and card.name == "br__grain" or (card.name == "br__analeptic" and player:hasSkill("br__wuchang")) or
          (card.name == "br__slash" and ld.hasPolicyorTrap(player, "armyfarming")) then
            if not player:prohibitUse(Fk:cloneCard("br__grain")) and not player:isProhibited(player, Fk:cloneCard("br__grain")) then
              return true
            end
          end
        end
      end
    else
      return player:hasSkill(self.name) and player:getMark("extra_slash-turn") > 0 and data.card.name == "br__slash"
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local use = player.room:askForUseCard(player, "grain", nil, "#grain-ask", true, nil, data)
      if use then
        self.cost_data = use
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if not ld.hasStandbyEquip(player, "camel") then --耦
        ld.addinstruction(player, -1)
      end
      local use = self.cost_data
      use.responseToEvent = data
      room:useCard(use)
    else
      room:setPlayerMark(player, "extra_slash-turn", 0)
      player:addCardUseHistory("slash", -1)
    end
  end,
}

Fk:addSkill(grainTrigger)

  local grainSkill = fk.CreateActiveSkill{
    name = "grain_skill",
    prompt = "#grain-ask",
    can_use = Util.FalseFunc,
    on_use = function(self, room, use)
      if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
        use.tos = { { use.from } }
      end
    end,
    on_effect = function(self, room, effect)
      local target = room:getPlayerById(effect.to)
      target:drawCards(2)
      room:addPlayerMark(target, "extra_slash-turn")
    end
  }

  local grain = fk.CreateBasicCard{
    name = "br__grain",
    skill = grainSkill,
  }

  extension:addCards({
    grain:clone(Card.Heart, 2),
    grain:clone(Card.Diamond, 2),
    grain:clone(Card.Diamond, 13),
  })


  Fk:loadTranslationTable{
    ["br__grain"] = "粮",
    [":br__grain"] = "<font color=\"#800020\"><b>指令牌</b></font><br/><b>时机</b>：摸牌阶段开始时<br/><b>目标</b>：你<br/><b>效果</b>：你摸两张牌，此回合下一次使用【杀】不计入次数限制。"..
    "<br/><font color=\"#800020\"><b>消耗指令：1</b></font>",
    ["#grain-ask"] = "你可以使用【粮】",
  }

--计谋牌
local UpraisingSkill = fk.CreateActiveSkill{
  name = "upraising_skill",
  prompt = "#upraising",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      room:addPlayerMark(to, "@upraising-turn")
  end,
}

local Upraising = fk.CreateTrickCard{
  name = "upraising",
  skill = UpraisingSkill,
  suit = Card.Spade,
  number = 1,
  is_derived = true,
}

extension:addCards({
  Upraising,
})

local upraising_buff = fk.CreateTriggerSkill{
  name = "#upraising_buff",
  mute = true,
  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self.name) and data.from and data.from == player then
      return player:getMark("@upraising-turn") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = data.damage + player:getMark("@upraising-turn")
    player.room:setPlayerMark(player, "@upraising-turn", 0)
  end,
}

Fk:addSkill(upraising_buff)

Fk:loadTranslationTable{
  ["upraising"] = "黄巾起义",
  [":upraising"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你于此回合下一次造成的伤害+1。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#upraising"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你于此回合下一次造成的伤害+1",
  ["@upraising-turn"] = "黄巾起义",
}

local MutinySkill = fk.CreateActiveSkill{
  name = "mutiny_skill",
  prompt = "#mutiny",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local Mutiny = fk.CreateTrickCard{
  name = "mutiny",
  skill = MutinySkill,
  suit = Card.Spade,
  number = 2,
  is_derived = true,
}

extension:addCards({
  Mutiny,
})

ld.addCardToTrap(Mutiny)

Fk:loadTranslationTable{
  ["mutiny"] = "兵变",
  [":mutiny"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：回合开始时，你视为对自己使用【杀】（不消耗指令）。<br/>你受到伤害之前，此牌不能被代替。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#tamehead"] = "<font color=\"#A7C7E7\"><b>【1费/毒计】</b></font>回合开始时，你视为对自己使用【杀】",
}


local RockfallTrigger = fk.CreateTriggerSkill{
  name = "#rockfall_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 2,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from ~= player.id and ((move.moveReason == fk.ReasonDiscard and player:getNextAlive().phase ~= Player.Discard)
      or move.moveReason == fk.ReasonPrey) then
        if player:hasSkill(self.name) and ld.hasinstructionfortrick(player, 1) and ld.hasTrickforuse(player, "br__rockfall") and
         not player:prohibitUse(Fk:cloneCard("br__rockfall")) then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "rockfall", nil, "#br__rockfall", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    ld.costinstructionfortrick(player, 1)
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(RockfallTrigger)

local RockfallSkill = fk.CreateActiveSkill{
  name = "br__rockfall_skill",
  prompt = "#br__rockfall",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    room:damage({
      from = player,
      to = target,
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })  
  end,
}

local Rockfall = fk.CreateTrickCard{
  name = "br__rockfall",
  skill = RockfallSkill,
  suit = Card.Spade,
  number = 3,
  is_derived = true,
}

extension:addCards({
  Rockfall,
})

Fk:loadTranslationTable{
  ["br__rockfall"] = "落井下石",
  [":br__rockfall"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手被你获得牌后或于弃牌阶段外弃置牌后<br/><b>目标</b>：对手<br/><b>效果</b>：你对其造成1点伤害。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#br__rockfall"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你可以使用【落井下石】造成1点伤害",
  ["#rockfall_trigger"] = "落井下石",
}

local TameHeadSkill = fk.CreateActiveSkill{
  name = "tamehead_skill",
  prompt = "#tamehead",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local player = room:getPlayerById(effect.from)
    local judge = {
      who = player,
      reason = "tamehead",
      pattern = ".|.|spade,club",
    }
    room:judge(judge)
    local result = judge.card
    if result.color == Card.Black then
      room:damage({
        from = player,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name
      })
    end
  end,
}

local TameHead = fk.CreateTrickCard{
  name = "tamehead",
  skill = TameHeadSkill,
  suit = Card.Spade,
  number = 4,
  is_derived = true,
}

extension:addCards({
  TameHead,
})

Fk:loadTranslationTable{
  ["tamehead"] = "降头术",
  [":tamehead"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你判定。若为黑色，你对其造成1点伤害。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#tamehead"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你判定。若为黑色，你对对手造成1点伤害",
}

--[[local EmpoisonTrigger = fk.CreateTriggerSkill{
  name = "#empoison_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 2,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and (data.card.name == "br__grain" or data.card.name == "br__analeptic") and
    ld.hasTrickforuse(player, "empoison") and not player:prohibitUse(Fk:cloneCard("empoison")) then
      local n = 1
      local logic = player.room.logic
      local current_event = logic:getCurrentEvent()
      local all_turn_events = logic.event_recorder[GameEvent.Turn]
      if type(all_turn_events) == "table" then
        local index = #all_turn_events
        if index > 1 then
          local turn_event = current_event:findParent(GameEvent.Turn)
          if turn_event ~= nil then
            index = index - 1
          end
          if index > 0 then
            current_event = all_turn_events[index]
            current_event:searchEvents(GameEvent.UseCard, 1, function (e)
              if e.data[1].from == player.id and table.contains(TargetGroup:getRealTargets(e.data[1].tos), target.id) then
                n = 3
              end
            end)
          end
        end
      end
      data.extra_data = data.extra_data or {}
      data.extra_data.empoison = n
      return ld.hasinstructionfortrick(player, n)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "empoison", nil, "#empoison", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    ld.costinstructionfortrick(player, data.extra_data.empoison)
    table.insertIfNeed(data.nullifiedTargets, target.id)
    local use = self.cost_data
    room:useCard(use)
  end,
}]]

local EmpoisonTrigger = fk.CreateTriggerSkill{
  name = "#empoison_trigger",
  anim_type = "offensive",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and ld.hasTrickforuse(player, "empoison") and not player:prohibitUse(Fk:cloneCard("empoison")) then
      return ld.hasinstructionfortrick(player, 3)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "empoison", nil, "#empoison", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    ld.costinstructionfortrick(player, 3)
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(EmpoisonTrigger)

local EmpoisonSkill = fk.CreateActiveSkill{
  name = "empoison_skill",
  prompt = "#empoison",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    room:damage({
      from = player,
      to = target,
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })
    room:setPlayerMark(target, "@@poison", 1)
  end,
}

local Empoison = fk.CreateTrickCard{
  name = "empoison",
  skill = EmpoisonSkill,
  suit = Card.Spade,
  number = 5,
  is_derived = true,
}

extension:addCards({
  Empoison,
})

Fk:loadTranslationTable{
  ["empoison"] = "下毒",
  [":empoison"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：回合结束时<br/><b>目标</b>：对手<br/><b>效果</b>：你对其造成1点伤害，且其下回合不能回复国力。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#empoison"] = "<font color=\"#A7C7E7\"><b>【3费】</b></font>你可以使用【下毒】",
  ["#empoison_trigger"] = "下毒",
}

local SurroundSkill = fk.CreateActiveSkill{
  name = "surround_skill",
  prompt = "#surround",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 3)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local Surround = fk.CreateTrickCard{
  name = "surround",
  skill = SurroundSkill,
  suit = Card.Spade,
  number = 6,
  is_derived = true,
}

extension:addCards({
  Surround,
})

ld.addCardToTrap(Surround)

Fk:loadTranslationTable{
  ["surround"] = "包围",
  [":surround"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你受到【杀】造成的伤害+1。<br/>你使用【杀】造成伤害之前，此牌不能被代替。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#surround"] = "<font color=\"#F8C8DC\"><b>【3费/毒计】</b></font>你受到【杀】造成的伤害+1",
}

local AmbushTrigger = fk.CreateTriggerSkill{
  name = "#ambush_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 2,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and ld.hasinstructionfortrick(player, 1) and ld.hasTrickforuse(player, "ambush") and
      not player:prohibitUse(Fk:cloneCard("ambush")) then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "ambush", nil, "#ambush", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    ld.costinstructionfortrick(player, 1)
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(AmbushTrigger)

local AmbushSkill = fk.CreateActiveSkill{
  name = "ambush_skill",
  prompt = "#ambush",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    room:damage({
      from = player,
      to = target,
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })  
    if target.phase == Player.Play then
      --target:endPlayPhase()
      room:addPlayerMark(target, "ambush-phase")
    end
  end,
}

local Ambush = fk.CreateTrickCard{
  name = "ambush",
  skill = AmbushSkill,
  suit = Card.Spade,
  number = 7,
  is_derived = true,
}

extension:addCards({
  Ambush,
})

Fk:loadTranslationTable{
  ["ambush"] = "伏兵",
  [":ambush"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手对你造成伤害后<br/><b>目标</b>：对手<br/><b>效果</b>：你对其造成1点伤害，若为其出牌阶段，则其此阶段不能对你使用牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#ambush"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你可以使用【伏兵】造成1点伤害",
  ["#ambush_trigger"] = "伏兵",
}

local BesiegeSkill = fk.CreateActiveSkill{
  name = "besiege_skill",
  prompt = "#besiege",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return to_select ~= Self.id and (#to:getCardIds(Player.Equip) > 0 or #to:getPile("#standby") > 0 or #to:getPile("sixdragon") > 0)
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      local player = room:getPlayerById(effect.from)
      --local id = room:askForCardChosen(player, to, "e", self.name)
      local id = ld.askForEquipChosen(self, room, player, to)
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      if Fk:getCardById(id).sub_type == Card.SubtypeArmor then
        room:setPlayerMark(player,"free_instruction", 1)
        room:useVirtualCard("br__slash", nil, player, to, self.name, true)
        room:setPlayerMark(player,"free_instruction", 0)
      end
  end,
}

local Besiege = fk.CreateTrickCard{
  name = "besiege",
  skill = BesiegeSkill,
  suit = Card.Spade,
  number = 8,
  is_derived = true,
}

extension:addCards({
  Besiege,
})

Fk:loadTranslationTable{
  ["besiege"] = "攻城",
  [":besiege"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你弃置其装备区内一张牌，若为防具牌，则你视为对其使用【杀】（不计入次数且不消耗指令）。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#besiege"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>你弃置对手装备区内一张牌，若为防具牌则你视为对其使用【杀】",
}

local FireAttackSkill = fk.CreateActiveSkill{
  name = "br__fire_attack_skill",
  prompt = "#br__fire_attack",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card, true)
    end
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, cardEffectEvent)
    local from = room:getPlayerById(cardEffectEvent.from)
    local to = room:getPlayerById(cardEffectEvent.to)
    if to:isKongcheng() then return end
    to:showCards(to:getCardIds(Player.Hand))
    local suits = {}
    for _, id in ipairs(to.player_cards[Player.Hand]) do
        local suit = Fk:getCardById(id):getSuitString()
        table.insertIfNeed(suits,suit)
    end
    local cards = room:askForDiscard(from, 1, 1, false, self.name, true,  ".|.|" .. table.concat(suits, ",") .."|hand" , "#fire_attack-throw")
    if #cards > 0 then
      local grains = table.filter(to:getCardIds({Player.Hand}), function(id)
        return Fk:getCardById(id).name == "br__grain" or Fk:getCardById(id).name == "br__analeptic" end)
      room:moveCardTo(grains, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true)
      room:damage({
        from = from,
        to = to,
        card = cardEffectEvent.card,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name
      })
    end
  end,
}

local FireAttack = fk.CreateTrickCard{
  name = "br__fire_attack",
  skill = FireAttackSkill,
  is_damage_card = true,
  suit = Card.Spade,
  number = 9,
  is_derived = true,
}

extension:addCards({
  FireAttack,
})

Fk:loadTranslationTable{
  ["br__fire_attack"] = "火攻",
  [":br__fire_attack"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你展示对手所有手牌，然后你可弃置一张与其中一张牌花色相同的手牌，若如此做，你弃置其中所有【粮】和【药】，然后你对其造成1点伤害。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#br__fire_attack"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你展示对手所有手牌，弃置一张与其中一张牌花色相同的手牌并对其造成伤害",
}

local duelSkill = fk.CreateActiveSkill{
  name = "br__duel_skill",
  prompt = "#br__duel",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local responsers = { to, from }
    local currentTurn = 1
    local currentResponser = to
    while currentResponser:isAlive() do
      local loopTimes = 1
      if effect.fixedResponseTimes then
        local canFix = currentResponser == to
        if effect.fixedAddTimesResponsors then
          canFix = table.contains(effect.fixedAddTimesResponsors, currentResponser.id)
        end
        if canFix then
          if type(effect.fixedResponseTimes) == 'table' then
            loopTimes = effect.fixedResponseTimes["slash"] or 1
          elseif type(effect.fixedResponseTimes) == 'number' then
            loopTimes = effect.fixedResponseTimes
          end
        end
      end
      local cardResponded
      for i = 1, loopTimes do
        local discards = room:askForDiscard(currentResponser, 1, 1, true, self.name, true, ".|.|.|.|br__slash", "#br__duel")
        if #discards > 0 then
          cardResponded = true
        else
          cardResponded = false
          break
        end
      end
      if not cardResponded then
        break
      end
      currentTurn = currentTurn % 2 + 1
      currentResponser = responsers[currentTurn]
    end
    if currentResponser:isAlive() then
      room:damage({
        from = responsers[currentTurn % 2 + 1],
        to = currentResponser,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end
}
local duel = fk.CreateTrickCard{
  name = "br__duel",
  suit = Card.Spade,
  number = 10,
  is_damage_card = true,
  is_derived = true,
  skill = duelSkill,
}

extension:addCards({
  duel,
})

Fk:loadTranslationTable{
  ["br__duel"] = "决斗",
  [":br__duel"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你令对手选择：1.弃置一张【杀】，然后令对手进行该选择；2.受到对方造成的1点伤害。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#br__duel"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你和对手轮流弃置一张【杀】，首先不如此做者受到1点伤害",
}

local SavageAssaultSkill = fk.CreateActiveSkill{
  name = "br__savage_assault_skill",
  prompt = "#br__savage_assault",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local cards = room:askForCard(to, 1, 2, true, self.name, true, ".|.|.|.|br__slash", "#sa-show")
    if #cards == 0 then
      ld.addinstruction(from, 1)
    else
      to:showCards(cards)
    end
    if #cards < 2 then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end
}
local SavageAssault = fk.CreateTrickCard{
  name = "br__savage_assault",
  suit = Card.Spade,
  number = 11,
  is_damage_card = true,
  is_derived = true,
  skill = SavageAssaultSkill,
}

extension:addCards({
  SavageAssault,
})

Fk:loadTranslationTable{
  ["br__savage_assault"] = "象阵",
  [":br__savage_assault"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：对手须展示至多两张【杀】，若少于两张则受到你造成的1点伤害，若未展示牌则你增加1点指令。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#br__savage_assault"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>对手须展示两张【杀】，否则受到1点伤害",
  ["#sa-show"] = "请展示一至两张【杀】，若少于两张/未展示，你受到1点伤害/对方增加1点指令",
}

local ArcheryAttackSkill = fk.CreateActiveSkill{
  name = "br__archery_attack_skill",
  prompt = "#br__archery_attack",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local cards = room:askForCard(to, 1, 2, true, self.name, true, ".|.|.|.|br__jink", "#aa-show")
    if #cards == 0 then
      ld.addinstruction(from, 1)
    else
      to:showCards(cards)
    end
    if #cards < 2 then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end
}
local ArcheryAttack = fk.CreateTrickCard{
  name = "br__archery_attack",
  suit = Card.Spade,
  number = 12,
  is_damage_card = true,
  is_derived = true,
  skill = ArcheryAttackSkill,
}

extension:addCards({
  ArcheryAttack,
})

Fk:loadTranslationTable{
  ["br__archery_attack"] = "箭雨",
  [":br__archery_attack"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：对手须展示至多两张【防】，若少于两张则受到你造成的1点伤害，若未展示牌则你增加1点指令。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#br__archery_attack"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>对手须展示两张【防】，否则受到1点伤害",
  ["#aa-show"] = "请展示一至两张【防】，若少于两张/未展示，你受到1点伤害/对方增加1点指令",
}

local DesperadoSkill = fk.CreateActiveSkill{
  name = "desperado_skill",
  prompt = "#desperado",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 3)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    room:damage({
      from = from,
      to = from,
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
    local n = from.hp < to.hp and 2 or 1
    room:damage({
      from = from,
      to = to,
      card = effect.card,
      damage = n,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
  end
}
local Desperado = fk.CreateTrickCard{
  name = "desperado",
  suit = Card.Spade,
  number = 13,
  is_damage_card = true,
  is_derived = true,
  skill = DesperadoSkill,
}

extension:addCards({
  Desperado,
})

Fk:loadTranslationTable{
  ["desperado"] = "死士",
  [":desperado"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你对自己造成1点伤害，然后若对手的国力多于你，则你对其造成2点伤害，否则你对其造成1点伤害。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#desperado"] = "<font color=\"#F8C8DC\"><b>【3费】</b></font>你对自己和对手依次造成1点伤害，对国力大于你的角色伤害+1",
}

local spreadrumorSkill = fk.CreateActiveSkill{
  name = "spreadrumor_skill",
  prompt = "#spreadrumor",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    room:setPlayerMark(target, "@@spreadrumor-turn", 1)
  end,
}

local spreadrumor = fk.CreateTrickCard{
  name = "spreadrumor",
  skill = spreadrumorSkill,
  suit = Card.Club,
  number = 1,
  is_derived = true,
}

extension:addCards({
  spreadrumor,
})

local spreadrumorTrigger = fk.CreateTriggerSkill{
  name = "#spreadrumor_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) then
      return ld.hasTrickforuse(player, "spreadrumor") and not player:prohibitUse(Fk:cloneCard("spreadrumor"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "spreadrumor", nil, "#spreadrumor", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(spreadrumorTrigger)

Fk:loadTranslationTable{
  ["spreadrumor"] = "散谣",
  [":spreadrumor"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手回合开始时<br/><b>目标</b>：对手<br/><b>效果</b>：令其本回合每次消耗指令观看计谋区/锻造区前判定，若为红桃则取消观看，若为黑桃则改为观看锻造区/计谋区。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#spreadrumor"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【散谣】",
  ["#spreadrumor_trigger"] = "散谣",
  ["@@spreadrumor-turn"] = "<font color=\"#E0BFB8\">散谣</font>",
}

local EightdiagramsSkill = fk.CreateActiveSkill{
  name = "eightdiagrams_skill",
  prompt = "#eightdiagrams",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local Eightdiagrams = fk.CreateTrickCard{
  name = "eightdiagrams",
  skill = EightdiagramsSkill,
  suit = Card.Club,
  number = 2,
  is_derived = true,
}

extension:addCards({
  Eightdiagrams,
})

ld.addCardToTrap(Eightdiagrams)

Fk:loadTranslationTable{
  ["eightdiagrams"] = "八门金锁",
  [":eightdiagrams"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你装备区内的牌和方案区的“方针”无效。<br/>此牌不能被代替，你的回合结束后弃置此牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#eightdiagrams"] = "<font color=\"#A7C7E7\"><b>【1费/毒计】</b></font>你装备区的牌和方针无效",
}

local EnticeleaveSkill = fk.CreateActiveSkill{
  name = "enticeleave_skill",
  prompt = "#enticeleave",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    --将对手方案区和装备区的所有牌置于其武将牌旁，你回合结束时按原样置回。（注意六龙骖驾！）
    local scenarios = to:getPile("#scenario&")--背面
    local policytrap = to:getPile("#scenario")--正面
    local equips = to:getCardIds(Player.Equip)--装备
    local standby = to:getPile("#standby")--备用
    local horses = to:getPile("sixdragon")--六龙骖驾
    room:setPlayerMark(to, "el_scenarios", scenarios)
    room:setPlayerMark(to, "el_policytrap", policytrap)
    room:setPlayerMark(to, "el_equips", equips)
    room:setPlayerMark(to, "el_standby", standby)
    room:setPlayerMark(to, "el_horses", horses)
    local removes = {}
    table.insertTable(removes, table.simpleClone(scenarios)) 
    table.insertTable(removes, table.simpleClone(policytrap)) 
    table.insertTable(removes, table.simpleClone(equips))
    table.insertTable(removes, table.simpleClone(standby))
    table.insertTable(removes, table.simpleClone(horses))
    local dummy = Fk:cloneCard("dilu")
    dummy:addSubcards(removes)
    room:moveCardTo(dummy, Card.Processing, nil, fk.ReasonJustMove, self.name)
    to:addToPile("enticeleave", dummy, false, "enticeleave")
  end
}

local enticeleave_clear = fk.CreateTriggerSkill{
  name = "#enticeleave_clear",
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    if target == player then
      local to = player:getNextAlive()
      return #to:getPile("enticeleave") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local to = player:getNextAlive()
    local dummy = Fk:cloneCard("dilu")
    dummy:addSubcards(to:getPile("enticeleave"))
    room:moveCardTo(dummy, Card.Processing, nil, fk.ReasonJustMove, self.name)
    if #to:getTableMark("el_scenarios") > 0 then
      for _, id in ipairs(to:getTableMark("el_scenarios")) do
        ld.enterScenario(self, to, id)
      end
    end
    if #to:getTableMark("el_policytrap") > 0 then
      for _, id in ipairs(to:getTableMark("el_policytrap")) do
        ld.enterScenario(self, to, id, true)
      end
    end
    if #to:getTableMark("el_equips") > 0 then
      for _, id in ipairs(to:getTableMark("el_equips")) do
        U.moveCardIntoEquip(room, to, id, "enticeleave")
      end
    end
    if #to:getTableMark("el_standby") > 0 then
      for _, id in ipairs(to:getTableMark("el_standby")) do
        ld.enterStandby(self, to, id)
      end
    end
    if #to:getTableMark("el_horses") > 0 then
      for _, id in ipairs(to:getTableMark("el_horses")) do
        to:addToPile("sixdragon", id)
      end
    end
  end,
}

Fk:addSkill(enticeleave_clear)

local Enticeleave = fk.CreateTrickCard{
  name = "enticeleave",
  suit = Card.Club,
  number = 3,
  is_derived = true,
  skill = EnticeleaveSkill,
}

extension:addCards({
  Enticeleave,
})

Fk:loadTranslationTable{
  ["enticeleave"] = "调虎离山",
  [":enticeleave"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：将其方案区和装备区的所有牌置于其武将牌旁，你回合结束时按原样置回。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#desperado"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>将对手方案区和装备区的所有牌置于其武将牌旁，你回合结束时按原样置回",
}

local CoercionSkill = fk.CreateActiveSkill{
  name = "coercion_skill",
  prompt = "#coercion",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    room:setPlayerMark(to, "weiya-phase", 1)
    room:setPlayerMark(to, "@@weiya_buff", 1)
  end
}

local Coercion = fk.CreateTrickCard{
  name = "coercion",
  suit = Card.Club,
  number = 4,
  is_derived = true,
  skill = CoercionSkill,
}

extension:addCards({
  Coercion,
})

local coercion_clear = fk.CreateTriggerSkill{
  name = "#coercion_clear",
  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@@weiya_buff") > 0 and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@weiya_buff", 0)
  end,
}

local coercion_buff = fk.CreateProhibitSkill{
  name = "#coercion_buff",
  prohibit_use = function(self, player, card)
    if player:getMark("weiya-phase") > 0 then
      return true
    end
  end,
  is_prohibited = function(self, from, to, card)
    if from and to then
      if from:getMark("@@weiya_buff") > 0 or from:getMark("@@emperor_hostage-turn") > 0 or from:getMark("ambush-phase") > 0 then
        return from.id ~= to.id
      end
      if (from:getMark("@@mislead-phase") > 0 or from:getMark("@@dizziness") > 0) and card.trueName == "slash" then
        return from.id ~= to.id
      end
    end
  end,
}

coercion_buff:addRelatedSkill(coercion_clear)
Fk:addSkill(coercion_buff)

Fk:loadTranslationTable{
  ["coercion"] = "威压",
  [":coercion"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：其本阶段不能使用牌，且下回合不能对你使用牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#coercion"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>对手本阶段不能使用牌，且下回合不能对你使用牌",
  ["#coercion_buff"] = "威压",
  ["@@weiya_buff"] = "<font color=\"#D8BFD8\">威压</font>",
}

local RecallSkill = fk.CreateActiveSkill{
  name = "recall_skill",
  prompt = "#recall",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    if target.phase == Player.Play then
      target:endPlayPhase()
    end
  end,
}

local Recall = fk.CreateTrickCard{
  name = "recall",
  skill = RecallSkill,
  suit = Card.Club,
  number = 5,
  is_derived = true,
}

extension:addCards({
  Recall,
})

local recallTrigger = fk.CreateTriggerSkill{
  name = "#recall_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and target.phase == Player.Play and ld.hasTrickforuse(player, "recall") then
      local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data[1]
        return use.from == target.id
      end, Player.HistoryPhase)
      return #events >= 3 and ld.hasinstructionfortrick(player, 2) and not player:prohibitUse(Fk:cloneCard("recall"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "recall", nil, "#recall", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    ld.costinstructionfortrick(player, 2)
    room:useCard(use)
  end,
}

Fk:addSkill(recallTrigger)

Fk:loadTranslationTable{
  ["recall"] = "召回",
  [":recall"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手于出牌阶段使用至少三张牌后。<br/><b>目标</b>：对手<br/><b>效果</b>：其结束本阶段。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#recall"] = "<font color=\"#ECFFDC\"><b>【2费】</b></font>你可以使用【召回】",
  ["#recall_trigger"] = "召回",
}

local honeytrapTrigger = fk.CreateTriggerSkill{
  name = "#honeytrap_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and target.phase == Player.Play then
      return ld.hasTrickforuse(player, "honey_trap") and not player:prohibitUse(Fk:cloneCard("honey_trap"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "honey_trap", nil, "#honey_trap", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(honeytrapTrigger)

local honey_trapSkill = fk.CreateActiveSkill{
  name = "honey_trap_skill",
  prompt = "#honey_trap",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    room:setPlayerMark(target, "@@honey_trap-phase", 1)
  end,
}

local honey_trap = fk.CreateTrickCard{
  name = "honey_trap",
  skill = honey_trapSkill,
  suit = Card.Club,
  number = 6,
  is_derived = true,
}

extension:addCards({
  honey_trap,
})

Fk:loadTranslationTable{
  ["honey_trap"] = "美人计",
  [":honey_trap"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手出牌阶段开始时<br/><b>目标</b>：对手<br/><b>效果</b>：其本阶段消耗指令从计谋区、锻造区获得牌时，你替其选择获得的牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#honey_trap"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【美人计】",
  ["#honeytrap_trigger"] = "美人计",
  ["@@honey_trap-phase"] = "<font color=\"#E37383\">美人计</font>",
}

local misleadTrigger = fk.CreateTriggerSkill{
  name = "#mislead_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and target.phase == Player.Play then
      return ld.hasTrickforuse(player, "mislead") and not player:prohibitUse(Fk:cloneCard("mislead"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "mislead", nil, "#mislead", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(misleadTrigger)

local misleadSkill = fk.CreateActiveSkill{
  name = "mislead_skill",
  prompt = "#mislead",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    local use = room:askForUseCard(target, "scout", "scout", "#mislead-scout", true)
    if use then
      room:useCard(use)
    else
      room:setPlayerMark(target, "@@mislead-phase", 1)
    end
  end,
}

local mislead = fk.CreateTrickCard{
  name = "mislead",
  skill = misleadSkill,
  suit = Card.Club,
  number = 7,
  is_derived = true,
}

Fk:loadTranslationTable{
  ["mislead"] = "误导",
  [":mislead"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手出牌阶段开始时<br/><b>目标</b>：对手<br/><b>效果</b>：其须使用一张【探】，否则其于此阶段不能对你使用【杀】和【射】。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#mislead"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【误导】",
  ["#mislead-scout"] = "误导：请使用一张【探】，否则此阶段不能使用【杀】和【射】。",
  ["#mislead_trigger"] = "误导",
  ["@@mislead-phase"] = "<font color=\"#D8BFD8\">误导</font>",
}

extension:addCards({
  mislead,
})

local plagueSkill = fk.CreateActiveSkill{
  name = "plague_skill",
  prompt = "#plague",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local plague = fk.CreateTrickCard{
  name = "plague",
  skill = plagueSkill,
  suit = Card.Club,
  number = 8,
  is_derived = true,
}

extension:addCards({
  plague,
})

ld.addCardToTrap(plague)
Fk:loadTranslationTable{
  ["plague"] = "瘟疫",
  [":plague"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：出牌阶段开始时，你进行判定，若为黑色，你指令-2。<br/>你使用【药】之前，此牌不能被代替"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#plague"] = "<font color=\"#A7C7E7\"><b>【1费/毒计】</b></font>出牌阶段开始时，你判定，黑色则指令-2",
}

local refugeeSkill = fk.CreateActiveSkill{
  name = "refugee_skill",
  prompt = "#refugee",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local refugee = fk.CreateTrickCard{
  name = "refugee",
  skill = refugeeSkill,
  suit = Card.Club,
  number = 9,
  is_derived = true,
}

ld.addCardToTrap(refugee)
extension:addCards({
  refugee,
})

Fk:loadTranslationTable{
  ["refugee"] = "难民",
  [":refugee"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：出牌阶段结束时，你进行判定，若为黑色，你指令-2。<br/>你使用【粮】之前，此牌不能被代替"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#refugee"] = "<font color=\"#A7C7E7\"><b>【1费/毒计】</b></font>出牌阶段结束时，你判定，黑色则指令-2",
}

local dismantlementSkill = fk.CreateActiveSkill{
  name = "dismantlement_skill",
  prompt = "#br__dismantlement",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    room:setPlayerMark(target, "@@dismantlement-phase", 1)
  end,
}

local dismantlement = fk.CreateTrickCard{
  name = "br__dismantlement",
  skill = dismantlementSkill,
  suit = Card.Club,
  number = 10,
  is_derived = true,
}

extension:addCards({
  dismantlement,
})

local dismantlementTrigger = fk.CreateTriggerSkill{
  name = "#dismantlement_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 1,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and target.phase == Player.Play then
      return ld.hasTrickforuse(player, "br__dismantlement") and not player:prohibitUse(Fk:cloneCard("br__dismantlement"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "dismantlement", nil, "#br__dismantlement", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(dismantlementTrigger)

local dismantlement_prohibit = fk.CreateProhibitSkill{
  name = "#dismantlement_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@@dismantlement-phase") ~= 0 then
      if card.type == Card.TypeBasic then
        return card.name ~= "shot__slash" and card.name ~= "br__analeptic"
      elseif card.type == Card.TypeTrick then
        return card.suit ~= Card.Diamond
      end
    end
  end,
}

Fk:addSkill(dismantlement_prohibit)

Fk:loadTranslationTable{
  ["br__dismantlement"] = "过河拆桥",
  [":br__dismantlement"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手出牌阶段开始时<br/><b>目标</b>：对手<br/><b>效果</b>：令其此阶段使用指令牌只能使用【射】和【药】、使用计谋牌只能使用方片牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#br__dismantlement"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【过河拆桥】",
  ["#dismantlement_trigger"] = "过河拆桥",
  ["#dismantlement_prohibit"] = "过河拆桥",
  ["@@dismantlement-phase"] = "<font color=\"#D8BFD8\">过河拆桥</font>",
}

local neglectarmySkill = fk.CreateActiveSkill{
  name = "neglectarmy_skill",
  prompt = "#neglectarmy",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local target = room:getPlayerById(effect.to)
    ld.addinstruction(target, -2)
  end,
}

local neglectarmy = fk.CreateTrickCard{
  name = "neglectarmy",
  skill = neglectarmySkill,
  suit = Card.Club,
  number = 11,
  is_derived = true,
}

extension:addCards({
  neglectarmy,
})

local neglectarmyTrigger = fk.CreateTriggerSkill{
  name = "#neglectarmy_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 1,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and target.phase == Player.Play then
      return ld.hasTrickforuse(player, "neglectarmy") and not player:prohibitUse(Fk:cloneCard("neglectarmy"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "neglectarmy", nil, "#neglectarmy", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(neglectarmyTrigger)

Fk:loadTranslationTable{
  ["neglectarmy"] = "怠军之计",
  [":neglectarmy"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手出牌阶段开始时<br/><b>目标</b>：对手<br/><b>效果</b>：其指令-2。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#neglectarmy"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【怠军之计】，令其指令-2",
  ["#neglectarmy_trigger"] = "怠军之计",
}

local ArmisticeSkill = fk.CreateActiveSkill{
  name = "armistice_skill",
  prompt = "#armistice",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    ld.enterScenario(self, to, effect.card:getEffectiveId(), true)
    room:handleAddLoseSkills(to, "armistice_use&")
  end,
}

local Armistice = fk.CreateTrickCard{
  name = "armistice",
  skill = ArmisticeSkill,
  suit = Card.Club,
  number = 12,
  is_derived = true,
}

extension:addCards({
  Armistice,
})

ld.addCardToPolicy(Armistice)

local armistice_use = fk.CreateViewAsSkill{
  name = "armistice_use&",
  mute = true,
  pattern = "br__analeptic",
  enabled_at_play = function(self, player)
    return ld.hasPolicyorTrap(player, "armistice")
  end,
  enabled_at_response = function(self, player, response)
    return ld.hasPolicyorTrap(player, "armistice") and not response
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and Fk:getCardById(to_select).name == "br__slash"
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then
      return nil
    end
    local c = Fk:cloneCard("br__analeptic")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end
}

local armistice_buff = fk.CreateProhibitSkill{
  name = "#armistice_buff",
  prohibit_use = function(self, player, card)
    if ld.hasPolicyorTrap(player, "armistice") or ld.hasPolicyorTrap(player:getNextAlive(), "armistice") then
      return card.trueName == "slash"
    end
  end,
}

Fk:addSkill(armistice_use)
Fk:addSkill(armistice_buff)

Fk:loadTranslationTable{
  ["armistice"] = "停战协议",
  ["@armistice"] = "<font color=\"#FF5F1F\">停战协议</font>",
  [":armistice"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>时机</b>：若此牌正面向上置于方案区<br/><b>效果</b>：你和对手不能使用【杀】和【射】。<br/>你可以将两张【杀】当【药】使用。<br/>你造成或受到伤害后弃置此牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#armistice"] = "<font color=\"#ECFFDC\"><b>【0费/方针】</b></font>你和对手不能使用【杀】和【射】，你可将两张【杀】当【药】使用",
  ["armistice_use&"] = "停战协议",
  ["#armistice_buff"] = "停战协议",
}

local EmperorhostageSkill = fk.CreateActiveSkill{
  name = "emperor_hostage_skill",
  prompt = "#emperor_hostage",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 4) and not player:isProhibited(player, card) and
    #table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@policy") > 0 end) == 0
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 4)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      ld.enterScenario(self, to, effect.card:getEffectiveId(), true)
  end,
}

local Emperorhostage = fk.CreateTrickCard{
  name = "emperor_hostage",
  skill = EmperorhostageSkill,
  suit = Card.Club,
  number = 13,
  is_derived = true,
}

extension:addCards({
  Emperorhostage,
})

ld.addCardToPolicy(Emperorhostage)

Fk:loadTranslationTable{
  ["emperor_hostage"] = "挟天子",
  ["@emperor_hostage"] = "<font color=\"#FF5F1F\">挟天子</font>",
  [":emperor_hostage"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>时机</b>：若此牌正面向上置于方案区<br/><b>效果</b>：对手的回合内，若其上回合对你使用过牌，则其此回合不能对你使用牌。<br/><font color=\"#D2042D\">方案区无方针计谋牌才可使用。</font>"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：4</b></font>",
  ["#emperor_hostage"] = "<font color=\"#ECFFDC\"><b>【4费/方针】</b></font>对手的回合内，若其上回合对你使用过牌，则其此回合不能对你使用牌。",
  ["#emperor_hostage_buff"] = "挟天子",
}


local BaitbookSkill = fk.CreateActiveSkill{
  name = "baitbook_skill",
  prompt = "#baitbook",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
  end,
}

local Baitbook = fk.CreateTrickCard{
  name = "baitbook",
  skill = BaitbookSkill,
  suit = Card.Heart,
  number = 1,
  is_derived = true,
}

extension:addCards({
  Baitbook,
})

ld.addCardToTrap(Baitbook)
Fk:loadTranslationTable{
  ["baitbook"] = "饵书",
  [":baitbook"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：当此牌离开你的方案区时，你弃置区域内四张没有“毒计”标识的牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#baitbook"] = "<font color=\"#ECFFDC\"><b>【2费/毒计】</b></font>离开方案区后你弃置四张牌",
}

local PartystruggleSkill = fk.CreateActiveSkill{
  name = "party_struggle_skill",
  prompt = "#party_struggle",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id and ld.hasEmptyScenario(Fk:currentRoom():getPlayerById(to_select))
  end,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:addToPile("#scenario", effect.card:getEffectiveId(), true, self.name)
    local mark = to:getTableMark("invalid_replace")
    table.insertIfNeed(mark, effect.card:getEffectiveId())
    room:setPlayerMark(to, "invalid_replace", mark)
  end,
}

local Partystruggle = fk.CreateTrickCard{
  name = "party_struggle",
  skill = PartystruggleSkill,
  suit = Card.Heart,
  number = 2,
  is_derived = true,
}

extension:addCards({
  Partystruggle,
})

ld.addCardToTrap(Partystruggle)
Fk:loadTranslationTable{
  ["party_struggle"] = "挑起党争",
  [":party_struggle"] = "<font color=\"#6400c8\"><b>计谋牌/毒计</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：当你使用“方针”标识的计谋牌后，你弃置之，然后弃置此牌。<br/>此牌不能被代替"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#party_struggle"] = "<font color=\"#A7C7E7\"><b>【1费/毒计】</b></font>你使用“方针”后弃置之",
}

local StealhorseSkill = fk.CreateActiveSkill{
  name = "stealhorse_skill",
  prompt = "#stealhorse",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    --获得对手装备区的坐骑牌，然后你可以弃置一张坐骑牌加１点指令。（注意六龙骖驾的马）
    local horses = table.simpleClone(table.filter(to:getCardIds(Player.Equip), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end))
    table.insertTable(horses, table.simpleClone(table.filter(to:getPile("#standby"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end)))
      table.insertTable(horses, table.simpleClone(table.filter(to:getPile("sixdragon"), function(id)
        return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end)))
    if #horses > 0 then
      local cid = room:askForCardChosen(from, to, {
        card_data = {
          {"horses", horses},
        }
      }, self.name)
      if cid ~= -1 then
        room:moveCardTo(cid, Card.PlayerHand, from, fk.ReasonPrey, self.name, "", true)
      end
    end
    local to_throw = table.simpleClone(table.filter(from:getCardIds("he"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end))
    table.insertTable(to_throw, table.simpleClone(table.filter(from:getPile("#standby"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end)))
    table.insertTable(to_throw, table.simpleClone(table.filter(from:getPile("sixdragon"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end)))    
    local cards, choice = U.askforChooseCardsAndChoice(from, to_throw, {"OK"}, "stealhorse", "你可以弃置一张坐骑牌加1点指令", {"cancel"})
    if #cards > 0 and choice == "OK" then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      ld.addinstruction(from, 1)
    end 
  end
}

local Stealhorse = fk.CreateTrickCard{
  name = "stealhorse",
  suit = Card.Heart,
  number = 3,
  is_derived = true,
  skill = StealhorseSkill,
}
  
  extension:addCards({
    Stealhorse,
  })

  Fk:loadTranslationTable{
    ["stealhorse"] = "盗马",
    [":stealhorse"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：获得其装备区的坐骑牌，然后你可弃置一张坐骑牌加1点指令。"..
    "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
    ["#stealhorse"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>获得对手装备区的坐骑牌",
    ["horses"] = "坐骑牌",
  }

local TrollSkill = fk.CreateActiveSkill{
  name = "troll_skill",
  prompt = "#troll",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    --to:showCards(to:getCardIds(Player.Hand))
    local suits = {}
    for _, id in ipairs(to:getCardIds(Player.Hand)) do
      local suit = Fk:getCardById(id):getSuitString()
      if suit ~= "nosuit" then
        table.insertIfNeed(suits, suit)
      end
    end
    --local choice = room:askForChoice(from, suits, "troll")
    local choice = U.askforViewCardsAndChoice(from, to:getCardIds(Player.Hand), suits, "troll", "troll-choose::"..effect.to)
    local cards = table.filter(to:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getSuitString() == choice end)
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
  end
}

local Troll = fk.CreateTrickCard{
  name = "troll",
  suit = Card.Heart,
  number = 4,
  is_derived = true,
  skill = TrollSkill,
}
  
  extension:addCards({
    Troll,
  })

  Fk:loadTranslationTable{
    ["troll"] = "搜查",
    [":troll"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你展示其所有手牌，然后弃置其中任意一种花色的所有手牌。"..
    "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
    ["#troll"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>展示对手的所有手牌，然后弃置其中任意一种花色的所有手牌。",
    ["troll-choose"] = "搜查：请选择一种花色，%dest弃置此花色的所有手牌。",
  }

local AutocraticSkill = fk.CreateActiveSkill{
  name = "autocratic_skill",
  prompt = "#autocratic",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    local target = player:getNextAlive()
    return ld.hasinstructionfortrick(player, 3 - #target:getPile("#scenario"))
  end,
  on_use = function(self, room, cardUseEvent)
    local target = room:getPlayerById(cardUseEvent.from):getNextAlive()
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3 - #target:getPile("#scenario"))
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    to:throwAllCards("h")
  end
}

local Autocratic = fk.CreateTrickCard{
  name = "autocratic",
  suit = Card.Heart,
  number = 5,
  is_derived = true,
  skill = AutocraticSkill,
}

extension:addCards({
  Autocratic,
})

Fk:loadTranslationTable{
  ["autocratic"] = "党锢",
  [":autocratic"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：弃置对手所有手牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>（对手的方案区每有一张正面朝上的计谋牌，此牌的消耗指令便-1。）",
  ["#autocratic"] = "<font color=\"#F8C8DC\"><b>【3费】</b></font>弃置对手所有手牌，对手每有一张计谋则少消耗1指令",
} 

local lure_enemySkill = fk.CreateActiveSkill{
  name = "lure_enemy_skill",
  prompt = "#lure_enemy",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    room:askForDiscard(target, 2, 2, true, self.name, false)
    room:addPlayerMark(player, "free_instruction")
    room:useVirtualCard("br__slash", nil, player, target, "lure_enemy", true) 
  end,
}

local lure_enemy = fk.CreateTrickCard{
  name = "lure_enemy",
  skill = lure_enemySkill,
  suit = Card.Heart,
  number = 6,
  is_derived = true,
}

extension:addCards({
  lure_enemy,
})

local lure_enemyTrigger = fk.CreateTriggerSkill{
  name = "#lure_enemy_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and data.card.name == "br__slash" and table.contains(TargetGroup:getRealTargets(data.tos), player.id) then
      return ld.hasTrickforuse(player, "lure_enemy") and ld.hasinstructionfortrick(player, 1) and not player:prohibitUse(Fk:cloneCard("lure_enemy"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "lure_enemy", nil, "#lure_enemy", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    ld.costinstructionfortrick(player, 1)
    room:useCard(use)
  end,
}

Fk:addSkill(lure_enemyTrigger)

Fk:loadTranslationTable{
  ["lure_enemy"] = "诱敌深入",
  [":lure_enemy"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手对你使用【杀】结算后<br/><b>目标</b>：对手<br/><b>效果</b>：其弃置两张牌，你视为对其使用一张不消耗指令的【杀】。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#lure_enemy"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你可以使用【诱敌深入】",
  ["#lure_enemy_trigger"] = "诱敌深入",
}

local gropefishSkill = fk.CreateActiveSkill{
  name = "gropefish_skill",
  prompt = "#gropefish",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    --local id = room:askForCardChosen(player, target, "he", self.name)
    local id = ld.askForCardChosen(self, room, player, target)
    room:obtainCard(player.id, id, false, fk.ReasonPrey)
  end,
}

local gropefish = fk.CreateTrickCard{
  name = "gropefish",
  skill = gropefishSkill,
  suit = Card.Heart,
  number = 7,
  is_derived = true,
}

extension:addCards({
  gropefish,
})

local gropefishTrigger = fk.CreateTriggerSkill{
  name = "#gropefish_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 3,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self.name) and not target:isNude() then
      return ld.hasTrickforuse(player, "gropefish") and not player:prohibitUse(Fk:cloneCard("gropefish"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "gropefish", nil, "#gropefish", true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    room:useCard(use)
  end,
}

Fk:addSkill(gropefishTrigger)

Fk:loadTranslationTable{
  ["gropefish"] = "浑水摸鱼",
  ["gropefish_skill"] = "浑水摸鱼",
  [":gropefish"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：对手受到伤害后<br/><b>目标</b>：对手<br/><b>效果</b>：你获得其一张牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#gropefish"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【浑水摸鱼】，获得其一张牌",
  ["#gropefish_trigger"] = "浑水摸鱼",
}

local StealpapersSkill = fk.CreateActiveSkill{
  name = "stealpapers_skill",
  prompt = "#stealpapers",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    local target = Fk:currentRoom():getPlayerById(to_select)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card) and
       #target:getPile("#scenario&") > 0 or #table.filter(target:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "baitbook" end) > 0
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 2)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    local cards = target:getPile("#scenario&") or {}
    if #table.filter(target:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "baitbook" end) > 0 then
      table.insert(cards, table.filter(target:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "baitbook" end)[1])
    end
    local id = player.room:askForCardChosen(player, target, {
      card_data = {
        {"#scenario&", cards},
      }
    }, self.name)
    room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true)
    ld.enterScenario(self, player, id)
  end
}

local Stealpapers = fk.CreateTrickCard{
  name = "stealpapers",
  suit = Card.Heart,
  number = 8,
  is_derived = true,
  skill = StealpapersSkill,
}
  
  extension:addCards({
    Stealpapers,
  })

  Fk:loadTranslationTable{
    ["stealpapers"] = "盗书",
    [":stealpapers"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：获得其方案区内的【饵书】或背面朝上的一张计谋牌。"..
    "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
    ["#stealpapers"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>获得对手方案区内的【饵书】或背面朝上的一张计谋牌。",
  }


local SnatchSkill = fk.CreateActiveSkill{
  name = "br__snatch_skill",
  prompt = "#br__snatch",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return to_select ~= user
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.to)
    --local id = room:askForCardChosen(player, target, "he", self.name)
    local id = ld.askForCardChosen(self, room, player, target)
    room:obtainCard(player.id, id, false, fk.ReasonPrey)
  end,
}

local Snatch = fk.CreateTrickCard{
  name = "br__snatch",
  skill = SnatchSkill,
  suit = Card.Heart,
  number = 9,
  is_derived = true,
}

extension:addCards({
  Snatch,
})
  
  local SnatchTrigger = fk.CreateTriggerSkill{
    name = "#br__snatch_trigger",
    anim_type = "offensive",
    mute = true,
    priority = 3,
    events = {fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(self.name) and data.card.trueName == "jink" then
        return ld.hasTrickforuse(player, "br__snatch") and not player:prohibitUse(Fk:cloneCard("br__snatch"))
      end
    end,
    on_cost = function(self, event, target, player, data)
      local use = player.room:askForUseCard(player, "snatch", nil, "#br__snatch", true, nil, data)
      if use then
        self.cost_data = use
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local use = self.cost_data
      room:useCard(use)
    end,
  }
  
  Fk:addSkill(SnatchTrigger)
  
  Fk:loadTranslationTable{
    ["br__snatch"] = "顺手牵羊",
    [":br__snatch"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：有角色使用【防】后<br/><b>目标</b>：对手<br/><b>效果</b>：你获得其一张牌。"..
    "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
    ["#br__snatch"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你可以使用【顺手牵羊】，获得其一张牌",
    ["#br__snatch_trigger"] = "顺手牵羊",
  }

local DefervesceneSkill = fk.CreateActiveSkill{
  name = "defervescene_skill",
  prompt = "#defervescene",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select and #Fk:currentRoom():getPlayerById(to_select):getCardIds("he") > 0
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 1)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local choices = {}
    if #to:getCardIds(Player.Hand) > 0 then
      table.insert(choices, "$Hand")
    end
    if #to:getCardIds(Player.Equip) > 0 or #to:getPile("#standby") > 0 or #to:getPile("sixdragon") > 0 then
      table.insert(choices, "$Equip")
    end
    local choice = room:askForChoice(from, choices, "defervescene", "", false, {"$Hand","$Equip"})
    if choice == "$Hand" then
      local n = math.min(#to:getCardIds(Player.Hand), 2)
      local cards = room:askForCardsChosen(from, to, n, n, "h", self.name)
      if #cards > 0 then
        room:throwCard(cards, self.name, to, from)
      end
    else
      --local id = room:askForCardChosen(from, to, "e", self.name)
      local id = ld.askForEquipChosen(self, room, from, to)
      if id ~= -1 then
        room:moveCardTo(id, Card.PlayerHand, from, fk.ReasonPrey, self.name, "", true, effect.from)
      end
    end
  end
}

local Defervescene = fk.CreateTrickCard{
  name = "defervescene",
  suit = Card.Heart,
  number = 10,
  is_derived = true,
  skill = DefervesceneSkill,
}
  
  extension:addCards({
    Defervescene,
  })

  Fk:loadTranslationTable{
    ["defervescene"] = "釜底抽薪",
    [":defervescene"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：你弃置其两张手牌或获得其装备区内的一张牌。"..
    "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
    ["#defervescene"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>弃置对手两张手牌，或获得对手装备区的一张牌。",
  }

local CollaborateSkill = fk.CreateActiveSkill{
  name = "collaborate_skill",
  prompt = "#collaborate",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select and #Fk:currentRoom():getPlayerById(to_select):getPile("#scenario") > 0
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    local target = player:getNextAlive()
    for _, id in ipairs(target:getPile("#scenario")) do
      if Fk:getCardById(id):getMark("@@policy") > 0 then
        return player:getMark("instruction") >= ld.policyCost(Fk:getCardById(id))
      end
    end
  end,
  on_use = function(self, room, cardUseEvent)
    room:setCardMark(cardUseEvent.card, "disresponsive", 1)
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local cards = table.filter(to:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@policy") > 0 and
      from:getMark("instruction") >= ld.policyCost(Fk:getCardById(id)) end)
    if #cards > 0 then
      local id = room:askForCardChosen(from, to, {
        card_data = {
          {"policy", cards},
        }
      }, "collaborate")
      ld.costinstructionfortrick(from, ld.policyCost(Fk:getCardById(id)))
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    end
  end
}

local Collaborate = fk.CreateTrickCard{
  name = "collaborate",
  suit = Card.Heart,
  number = 11,
  is_derived = true,
  skill = CollaborateSkill,
}
  
  extension:addCards({
    Collaborate,
  })

  Fk:loadTranslationTable{
    ["collaborate"] = "里应外合",
    [":collaborate"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：弃置其方案区的一张“方针”标识的正面朝上计谋牌。"..
    "<br/><b>此牌消耗指令等于被弃置牌消耗指令</b></font><br/>此牌不能被【破】抵消。",
    ["#collaborate"] = "弃置对手方案区的一张“方针”标识的正面朝上计谋牌并消耗等量指令",
  }


local BeatSwordsSkill = fk.CreateActiveSkill{
  name = "beat_swords_skill",
  prompt = "#beat_swords",
  mod_target_filter = function(self, to_select, selected, user, card)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  target_num = 1,
  can_use = function(self, player)
    return ld.hasinstructionfortrick(player, 3)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3)
  end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    --to:throwAllCards("e")
    local equips = to:getCardIds(Player.Equip)
    table.insertTable(equips, to:getPile("#standby"))
    table.insertTable(equips, to:getPile("sixdragon"))
    if #equips > 0 then
      local dummy = Fk:cloneCard("br__jink")
      dummy:addSubcards(equips)
      --room:moveCardTo(dummy, Card.DiscardPile, nil, fk.ReasonDiscard, "beat_swords", nil, false, player.id)
      room:moveCardTo(dummy, Card.DiscardPile, nil, fk.ReasonDiscard, "beat_swords", "", true, effect.from)
    end
    local card = room:getCardsFromPileByRule("grain", 1, "discardPile")
    if #card > 0 then
      room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonJustMove, self.name)
    end
  end
}

local BeatSwords = fk.CreateTrickCard{
  name = "beat_swords",
  suit = Card.Heart,
  number = 12,
  is_derived = true,
  skill = BeatSwordsSkill,
}

extension:addCards({
  BeatSwords,
})

Fk:loadTranslationTable{
  ["beat_swords"] = "铸剑为犁",
  [":beat_swords"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：对手<br/><b>效果</b>：弃置其装备区的所有牌，然后其从弃牌堆获得一张【粮】。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#beat_swords"] = "<font color=\"#F8C8DC\"><b>【3费】</b></font>弃置对手装备区的所有牌，然后其从弃牌堆获得一张【粮】。",
} 

local BorrowingjingzhouSkill = fk.CreateActiveSkill{
  name = "borrowingjingzhou_skill",
  prompt = "#borrowingjingzhou",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 2) and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local player = room:getPlayerById(effect.to)
      ld.enterScenario(self, player, effect.card:getEffectiveId(), true)
      local mark = player:getTableMark("invalid_replace")
      table.insertIfNeed(mark, effect.card:getEffectiveId())
      room:setPlayerMark(player, "invalid_replace", mark)
      local target = player:getNextAlive()
      local equips = #target:getCardIds(Player.Equip) + #target:getPile("#standby") + #target:getPile("sixdragon") 
      local n = math.min(equips, 2)
      local cards = {}
      if n > 0 then
      local equip = ld.askForEquipChosen(self, room, player, target, 1, 2)
        if #equip > 0 then
          table.insertTable(cards, equip)
        end
      end
      if not target:isKongcheng() then
        local ids = room:askForCardsChosen(player, target, 1, 1, "h", "borrowingjingzhou")
        table.insertTable(cards, ids)
      end
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, effect.to)
  end,
}

local Borrowingjingzhou = fk.CreateTrickCard{
  name = "borrowingjingzhou",
  skill = BorrowingjingzhouSkill,
  suit = Card.Heart,
  number = 13,
  is_derived = true,
}

extension:addCards({
  Borrowingjingzhou,
})

ld.addCardToPolicy(Borrowingjingzhou)

Fk:loadTranslationTable{
  ["borrowingjingzhou"] = "借荆州",
  ["@borrowingjingzhou"] = "<font color=\"#FF5F1F\">借荆州</font>",
  [":borrowingjingzhou"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>效果</b>：你使用此牌后，你获得对手装备区内至多两张牌和一张手牌。<br/>对手对你造成伤害后，你弃置此牌然后交给其两张牌。<br/>此牌不能被代替。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#borrowingjingzhou"] = "<font color=\"#ECFFDC\"><b>【2费/方针】</b></font>你获得对手装备区内至多两张牌和一张手牌",
}

local TyrannySkill = fk.CreateActiveSkill{
  name = "tyranny_skill",
  prompt = "#tyranny",
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return true
  end,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card) and ld.hasinstructionfortrick(player, 4)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
    room:setCardMark(cardUseEvent.card, "disresponsive", 1)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 4)
  end,
  on_effect = function(self, room, effect)
      local player = room:getPlayerById(effect.to)
      player:drawCards(8, self.name)
      player:skip(Player.Discard)
  end
}

local Tyranny = fk.CreateTrickCard{
  name = "tyranny",
  skill = TyrannySkill,
}

extension:addCards({
  Tyranny:clone(Card.Diamond, 1),
})

Fk:loadTranslationTable{
  ["tyranny"] = "苛政",
  [":tyranny"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你摸八张牌，然后跳过本回合弃牌阶段。此牌不能被【破】抵消。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：4</b></font>",
  ["#tyranny"] = "<font color=\"#FFF8DC\"><b>【4费】</b></font>你摸八张牌，然后跳过本回合弃牌阶段",
} 

local BorrowarrowsTrigger = fk.CreateTriggerSkill{
  name = "#borrowarrows_trigger",
  anim_type = "defensive",
  mute = true,
  priority = 1,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    if data.to ~= player.id then return false end
    if data.card.name == "shot__slash" or (data.card.type == Card.TypeTrick and data.card.suit == Card.Spade) then
      return ld.hasTrickforuse(player, "borrowarrows") and ld.hasinstructionfortrick(player, 1)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askForUseCard(player, "borrowarrows", nil, "#borrowarrows-ask:::" .. data.card:toLogString() , true, nil, data)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    ld.costinstructionfortrick(player, 1)
    local use = self.cost_data
    use.toCard = data.card
    use.responseToEvent = data
    room:useCard(use)
  end,
}

Fk:addSkill(BorrowarrowsTrigger)

local BorrowarrowsSkill = fk.CreateActiveSkill{
  name = "borrowarrows_skill",
  can_use = Util.FalseFunc,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if effect.responseToEvent then
      if room:getTag("rumble_effected") then
          room:setTag("rumble_effected", false)
      else
        if effect.toCard.type == Card.TypeBasic then
          effect.responseToEvent.isCancellOut = true
        else
          table.insertIfNeed(effect.responseToEvent.nullifiedTargets, player.id)
        end
      end
    end
    if player:isAlive() then
      if effect.toCard.type == Card.TypeBasic then
        room:moveCardTo(effect.toCard, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
      elseif effect.toCard.type == Card.TypeTrick then
        ld.enterScenario(self, player, effect.toCard:getEffectiveId())
      end
    end
  end,
}

local Borrowarrows = fk.CreateTrickCard{
  name = "borrowarrows",
  skill = BorrowarrowsSkill,
  suit = Card.Diamond,
  number = 2,
  is_derived = true,
}

extension:addCards({
  Borrowarrows,
})

Fk:loadTranslationTable{
  ["borrowarrows"] = "草船借箭",
  [":borrowarrows"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：【射】或伤害类计谋牌对你生效前<br/><b>目标</b>：此牌<br/><b>效果</b>：抵消并获得之。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#borrowarrows-ask"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你可以使用【草船借箭】抵消%arg",
  ["#borrowarrows_trigger"] = "草船借箭",
}

local EncyclopediaSkill = fk.CreateActiveSkill{
  name = "encyclopedia_skill",
  prompt = "#encyclopedia",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local ld_tricks = room:getBanner("@$tricks") or {}
    if #ld_tricks > 0 then
      local cards = table.random(ld_tricks, 2)
      if #cards > 0 then
        for i = 1, #cards, 1 do
          ld.enterScenario(self, to, cards[i])
        end
      end
      room:setPlayerMark(to, "encyclopedia-turn", cards)
    end
  end,
}

local Encyclopedia = fk.CreateTrickCard{
  name = "encyclopedia",
  skill = EncyclopediaSkill,
  suit = Card.Diamond,
  number = 3,
  is_derived = true,
}

local encyclopedia_buff = fk.CreateProhibitSkill{
  name = "#encyclopedia_buff",
  prohibit_use = function(self, player, card)
    if #player:getTableMark("encyclopedia-turn") == 0 then return false end
    if table.contains(player:getTableMark("encyclopedia-turn"), card:getEffectiveId()) then
      return true
    end
  end,
}

Fk:addSkill(encyclopedia_buff)

extension:addCards({
  Encyclopedia,
})

Fk:loadTranslationTable{
  ["encyclopedia"] = "修撰大典",
  [":encyclopedia"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你从计谋区摸两张牌。且此回合不能使用这些牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#encyclopedia"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你从计谋区摸两张牌。且此回合不能使用这些牌",
  ["#encyclopedia_buff"] = "修撰大典",
}

local JingshanjadeSkill = fk.CreateActiveSkill{
  name = "jingshanjade_skill",
  prompt = "#jingshanjade",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 1) and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      local ld_equips = room:getBanner("@$equips") or {}
      local treasures = table.filter(ld_equips, function(id) return Fk:getCardById(id).sub_type == Card.SubtypeTreasure end)
      if #treasures > 0 then
        local id = room:askForCardChosen(to, to, {
          card_data = {
            { "treasure", treasures }
          }
        }, self.name)
        if id ~= -1 then
          table.removeOne(ld_equips, id)
          table.shuffle(ld_equips)
          room:setBanner("@$equips", ld_equips)
          room:moveCardTo(id, Card.PlayerHand, to, fk.ReasonJustMove, self.name)
        end
      end
  end,
}

local Jingshanjade = fk.CreateTrickCard{
  name = "jingshanjade",
  skill = JingshanjadeSkill,
  suit = Card.Diamond,
  number = 4,
  is_derived = true,
}

extension:addCards({
  Jingshanjade,
})

Fk:loadTranslationTable{
  ["jingshanjade"] = "荆山玉出",
  [":jingshanjade"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你观看锻造区所有牌，获得其中一张宝物牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#jingshanjade"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你观看锻造区所有牌，获得其中一张宝物牌",
}

local GodsalvationSkill = fk.CreateActiveSkill{
  name = "br__god_salvation_skill",
  prompt = "#br__god_salvation",
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return true
  end,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card) and ld.hasinstructionfortrick(player, 4 - player.hp)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 4 - room:getPlayerById(cardUseEvent.from).hp)
  end,
  on_effect = function(self, room, effect)
      local player = room:getPlayerById(effect.to)
      room:recover({
        who = player,
        num = 4 - player.hp,
        card = effect.card,
        recoverBy = player,
        skillName = self.name
      })
  end
}

local Godsalvation = fk.CreateTrickCard{
  name = "br__god_salvation",
  skill = GodsalvationSkill,
}

extension:addCards({
  Godsalvation:clone(Card.Diamond, 5),
})

Fk:loadTranslationTable{
  ["br__god_salvation"] = "桃园结义",
  [":br__god_salvation"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你将国力恢复至上限。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：4</b></font>（你每有1点国力，此牌的消耗指令便-1）",
  ["#br__god_salvation"] = "<font color=\"#FFF8DC\"><b>【4费】</b></font>你将国力恢复至上限，每有1点国力则少消耗1指令",
} 

local SpeedpreciousSkill = fk.CreateActiveSkill{
  name = "speedprecious_skill",
  prompt = "#speedprecious",
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return true
  end,
  can_use = function(self, player, card)
    return false
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3)
  end,
  on_effect = function(self, room, effect)
      local player = room:getPlayerById(effect.to)
      player:drawCards(2)
      room:setPlayerMark(player, "speedprecious-phase", 2)
  end
}

local Speedprecious = fk.CreateTrickCard{
  name = "speedprecious",
  skill = SpeedpreciousSkill,
  suit = Card.Diamond,
  number = 6,
  is_derived = true,
}

extension:addCards({
  Speedprecious,
})

local SpeedpreciousTrigger = fk.CreateTriggerSkill{
  name = "#speedprecious_trigger",
  anim_type = "offensive",
  mute = true,
  priority = 4,
  events = {fk.EventPhaseStart, fk.CardUsing, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) then
      if event == fk.EventPhaseStart then
        return ld.hasTrickforuse(player, "speedprecious") and player.phase == Player.Play and ld.hasinstructionfortrick(player, 3) and not player:prohibitUse(Fk:cloneCard("speedprecious"))
      elseif event == fk.CardUsing then
        return player:getMark("speedprecious-phase") > 0 and data.card.trueName == "slash"
      elseif event == fk.Damage then
        return data.card and data.card.trueName == "slash" and data.card:getMark("speedprecious-phase") ~= 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local use = player.room:askForUseCard(player, "speedprecious", nil, "#speedprecious", true, nil, data)
      if use then
        self.cost_data = use
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local use = self.cost_data
      room:useCard(use)
    elseif event == fk.CardUsing then
      room:removePlayerMark(player, "speedprecious-phase", 1)
      room:setCardMark(data.card, "speedprecious-phase", 1)
      player:addCardUseHistory(data.card.trueName, -1)
    elseif event == fk.Damage then
      ld.addinstruction(player, 1)
      room:setCardMark(data.card, "speedprecious-phase", 0)
    end
  end,
}

Fk:addSkill(SpeedpreciousTrigger)

Fk:loadTranslationTable{
  ["speedprecious"] = "兵贵神速",
  [":speedprecious"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段开始时<br/><b>目标</b>：你<br/><b>效果</b>：摸两张牌，本阶段你使用的前两张【杀】和【射】：无次数限制、造成伤害后你指令+1。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#speedprecious"] = "<font color=\"#F8C8DC\"><b>【3费】</b></font>你可以使用【兵贵神速】，摸两张牌且使用【杀】次数上限+2",
  ["#speedprecious_trigger"] = "兵贵神速",
}

local GatherarmySkill = fk.CreateActiveSkill{
  name = "gatherarmy_skill",
  prompt = "#gatherarmy",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 1) and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 1)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      local card = room:getCardsFromPileByRule("slash", 2, "discardPile")
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonJustMove, self.name)
      end
      room:addPlayerMark(to, "AddMaxCards-turn", 2)
  end,
}

local Gatherarmy = fk.CreateTrickCard{
  name = "gatherarmy",
  skill = GatherarmySkill,
  suit = Card.Diamond,
  number = 7,
  is_derived = true,
}

extension:addCards({
  Gatherarmy,
})

Fk:loadTranslationTable{
  ["gatherarmy"] = "大点兵",
  [":gatherarmy"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：从弃牌堆获得两张【杀】，本回合手牌上限+2。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：1</b></font>",
  ["#gatherarmy"] = "<font color=\"#A7C7E7\"><b>【1费】</b></font>你从弃牌堆获得两张【杀】，本回合手牌上限+2。",
}

local SecretadvanceSkill = fk.CreateActiveSkill{
  name = "secretadvance_skill",
  prompt = "#secretadvance",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      room:setPlayerMark(to, "secretadvance-phase", 1)--耦合开始
  end,
}

local Secretadvance = fk.CreateTrickCard{
  name = "secretadvance",
  skill = SecretadvanceSkill,
  suit = Card.Diamond,
  number = 8,
  is_derived = true,
}

extension:addCards({
  Secretadvance,
})

Fk:loadTranslationTable{
  ["secretadvance"] = "暗度陈仓",
  [":secretadvance"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：本阶段你使用的下一张计谋牌的消耗指令-2。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#secretadvance"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>本阶段你使用的下一张计谋牌的消耗指令-2",
}

local RetreatSkill = fk.CreateActiveSkill{
  name = "retreat_skill",
  prompt = "#retreat",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      ld.addinstruction(to, 2)
      room.logic:breakTurn()
  end,
}

local Retreat = fk.CreateTrickCard{
  name = "retreat",
  skill = RetreatSkill,
  suit = Card.Diamond,
  number = 9,
  is_derived = true,
}

extension:addCards({
  Retreat,
})

Fk:loadTranslationTable{
  ["retreat"] = "鸣金收兵",
  [":retreat"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你+2指令，结束此回合。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#retreat"] = "<font color=\"#ECFFDC\"><b>【0费】</b></font>你+2指令，结束此回合",
}

local AdoptstrategiesSkill = fk.CreateActiveSkill{
  name = "adoptstrategies_skill",
  prompt = "#adoptstrategies",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 3) and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 3)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    ld.enterScenario(self, to, effect.card:getEffectiveId(), true)
  end,
}

local Adoptstrategies = fk.CreateTrickCard{
  name = "adoptstrategies",
  skill = AdoptstrategiesSkill,
  suit = Card.Diamond,
  number = 10,
  is_derived = true,
}

extension:addCards({
  Adoptstrategies,
})

ld.addCardToPolicy(Adoptstrategies)
Fk:loadTranslationTable{
  ["adoptstrategies"] = "广纳良策",
  ["@adoptstrategies"] = "<font color=\"#FF5F1F\">广纳良策</font>",
  [":adoptstrategies"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>时机</b>：若此牌正面向上置于方案区<br/><b><b>效果</b>：对手每回合首次从计谋区发现牌后，你可以观看其余牌并获得其中一张。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：3</b></font>",
  ["#adoptstrategies"] = "<font color=\"#F8C8DC\"><b>【3费/方针】</b></font>对手每回合首次从计谋区发现牌后，你可以观看其余牌并获得其中一张",
}

local ArmyfarmingSkill = fk.CreateActiveSkill{
  name = "armyfarming_skill",
  prompt = "#armyfarming",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    ld.enterScenario(self, to, effect.card:getEffectiveId(), true)
    room:handleAddLoseSkills(to, "armyfarming_use&")
  end,
}

local Armyfarming = fk.CreateTrickCard{
  name = "armyfarming",
  skill = ArmyfarmingSkill,
  suit = Card.Diamond,
  number = 11,
  is_derived = true,
}

extension:addCards({
  Armyfarming,
})

ld.addCardToPolicy(Armyfarming)

local armyfarming_use = fk.CreateViewAsSkill{
  name = "armyfarming_use&",
  mute = true,
  pattern = ".|.|.|.|br__grain",
  enabled_at_play = function(self, player)
    return ld.hasPolicyorTrap(player, "armyfarming")
  end,
  enabled_at_response = function(self, player, response)
    return ld.hasPolicyorTrap(player, "armyfarming") and Fk.currentResponsePattern == "grain"
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).name == "br__slash"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("br__grain")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end
}

Fk:addSkill(armyfarming_use)

Fk:loadTranslationTable{
  ["armyfarming"] = "屯田制",
  ["@armyfarming"] = "<font color=\"#FF5F1F\">屯田制</font>",
  [":armyfarming"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>时机</b>：若此牌正面向上置于方案区<br/><b><b>效果</b>：你可将【杀】当【粮】使用。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：0</b></font>",
  ["#armyfarming"] = "<font color=\"#ECFFDC\"><b>【0费/方针】</b></font>你可以将【杀】当【粮】使用",
  ["armyfarming_use&"] = "屯田制",
}

local AstrologySkill = fk.CreateActiveSkill{
  name = "astrology_skill",
  prompt = "#astrology",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 2) and not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 2)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local ld_tricks = room:getBanner("@$tricks") or {}
    if #ld_tricks > 0 then
      local id = room:askForCardChosen(to, to, {
        card_data = {
          { self.name, ld_tricks }
        }
      }, self.name)
      if id ~= -1 then
        ld.enterScenario(self, to, id)
      end
    end
  end,
}

local Astrology = fk.CreateTrickCard{
  name = "astrology",
  skill = AstrologySkill,
  suit = Card.Diamond,
  number = 12,
  is_derived = true,
}

extension:addCards({
  Astrology,
})

Fk:loadTranslationTable{
  ["astrology"] = "观星",
  ["astrology_skill"] = "观星",
  [":astrology"] = "<font color=\"#6400c8\"><b>计谋牌</b></font><br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br/><b>效果</b>：你观看计谋区所有牌，获得其中一张牌。"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：2</b></font>",
  ["#astrology"] = "<font color=\"#CCCCFF\"><b>【2费】</b></font>你观看计谋区所有牌，获得其中一张牌",
}


local FlourishingSkill = fk.CreateActiveSkill{
  name = "flourishing_skill",
  prompt = "#flourishing",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return ld.hasinstructionfortrick(player, 4) and not player:isProhibited(player, card) and
    #table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@policy") > 0 end) == 0
  end,
  on_use = function(self, room, cardUseEvent)
    ld.costinstructionfortrick(room:getPlayerById(cardUseEvent.from), 4)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = { { cardUseEvent.from } }
    end
  end,
  on_effect = function(self, room, effect)
      local to = room:getPlayerById(effect.to)
      ld.enterScenario(self, to, effect.card:getEffectiveId(), true)
  end,
}

local Flourishing = fk.CreateTrickCard{
  name = "flourishing",
  skill = FlourishingSkill,
  suit = Card.Diamond,
  number = 13,
  is_derived = true,
}

extension:addCards({
  Flourishing,
})

ld.addCardToPolicy(Flourishing)

Fk:loadTranslationTable{
  ["flourishing"] = "蒸蒸日上",
  ["@flourishing"] = "<font color=\"#FF5F1F\">蒸蒸日上</font>",
  [":flourishing"] = "<font color=\"#6400c8\"><b>计谋牌/方针</b></font><br/><b>时机</b>：若此牌正面向上置于方案区<br/><b>效果</b>：回合开始时，你可回复1点国力或摸两张牌。<br/><font color=\"#D2042D\">方案区无方针计谋牌才可使用。</font>"..
  "<br/><font color=\"#6400c8\"><b>消耗指令：4</b></font>",
  ["#flourishing"] = "<font color=\"#ECFFDC\"><b>【4费/方针】</b></font>回合开始时，你可回复1点国力或摸两张牌",
  ["hprecover"] = "回复1点国力",
  ["draw2"] = "摸两张牌", 
}

--方针
local policy_skills = fk.CreateTriggerSkill{
  name = "#policy_skill",
  mute = true,
  priority = 2,
  events = {fk.TurnStart, fk.Damage, fk.Damaged, fk.AfterCardsMove, "fk.EndDiscover"},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("policy_invalid") > 0 or ld.hasPolicyorTrap(player, "eightdiagrams") then return false end
    if event == fk.TurnStart then
      return (target == player and ld.hasPolicyorTrap(player, "flourishing")) or
      (target ~= player and ld.hasPolicyorTrap(player, "emperor_hostage"))
    elseif event == fk.Damage then
      return target == player and ld.hasPolicyorTrap(player, "armistice")
    elseif event == fk.Damaged then
      if target == player then
        return (ld.hasPolicyorTrap(player, "borrowingjingzhou") and data.from ~= player) or ld.hasPolicyorTrap(player, "armistice")
      end
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial and 
            (Fk:getCardById(info.cardId).name == "armyfarming" or Fk:getCardById(info.cardId).name == "armistice") then
              return true
            end
          end
        end
      end
    elseif event == "fk.EndDiscover" then
      return target ~= player and ld.hasPolicyorTrap(player, "adoptstrategies") and player:getMark("adoptstrategies-turn") == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      if target == player and ld.hasPolicyorTrap(player, "flourishing") then
        ld.invokePolicyorTrap(player, "flourishing")
        local choices =  {"draw2", "hprecover"}
        if not player:isWounded() then table.removeOne(choices, "hprecover") end
        local choice = room:askForChoice(player, choices, "flourishing")
        if choice == "draw2" then
          player:drawCards(2, "flourishing")
        else
          room:recover({
            who = player,
            num = 1,
            recoverBy = player,
            skillName = "flourishing"
          })
        end
      elseif target ~= player and ld.hasPolicyorTrap(player, "emperor_hostage") then
        local turn_event = room.logic:getCurrentEvent()
        if not turn_event then return false end
        local x = target:getMark("emperor_hostage_record")
        if x == 0 then
          local events = room.logic.event_recorder[GameEvent.Turn] or Util.DummyTable
          for _, e in ipairs(events) do
            local current_player = e.data[1]
            if current_player == target then
              x = e.id
              room:setPlayerMark(target, "emperor_hostage_record", x)
              break
            end
          end
        end
        local turn_events = U.getEventsByRule(room, GameEvent.Turn, 2, function(e)
          local current_player = e.data[1]
          return current_player == target
        end, x)
        if #turn_events > 1 then
          turn_events[#turn_events]:searchEvents(GameEvent.UseCard, 1, function (e)
            if e.data[1].from == target.id and table.contains(TargetGroup:getRealTargets(e.data[1].tos), player.id) then
              ld.invokePolicyorTrap(target, "emperor_hostage")
              room:setPlayerMark(target, "@@emperor_hostage-turn", 1)
            end
          end)
        end
      end
    elseif event == fk.Damage then
      if ld.hasPolicyorTrap(player, "armistice") then
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "armistice" end)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      end
    elseif event == fk.Damaged then
      if ld.hasPolicyorTrap(player, "borrowingjingzhou") and data.from ~= player then
        ld.invokePolicyorTrap(player, "borrowingjingzhou")
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "borrowingjingzhou" end)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
        local n = math.min(#player:getCardIds("he"), 2)
        local cards = room:askForCard(player, n, n, true, self.name, false, ".", "#bj-give::"..data.from.id)
        room:moveCardTo(cards, Player.Hand, data.from, fk.ReasonGive, "borrowingjingzhou")
      end
      if ld.hasPolicyorTrap(player, "armistice") then
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "armistice" end)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      end
    elseif event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "armyfarming" then
              room:handleAddLoseSkills(player, "-armyfarming_use&")
            elseif Fk:getCardById(info.cardId).name == "armistice" then
              room:handleAddLoseSkills(player, "-armistice_use&")
            end
          end
        end
    elseif event == "fk.EndDiscover" then
      ld.invokePolicyorTrap(player, "adoptstrategies")
      room:addPlayerMark(player, "adoptstrategies-turn")
      if #data.ids > 0 then
        local id = room:askForCardChosen(player, target, {
          card_data = {
            { self.name, data.ids }
          }
        }, self.name)
        if id ~= -1 then
          ld.enterScenario(self, player, id)
        end 
      end
    end
  end,

  refresh_events = {fk.TurnStart, fk.TurnEnd, fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart or event == fk.TurnEnd then
      return target == player and #player:getPile("#scenario") > 0
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial and 
            Fk:getCardById(info.cardId):getMark("@@policy") ~= 0 then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      for _, id in ipairs(player:getPile("#scenario")) do
        if Fk:getCardById(id):getMark("@@policy") ~= 0 then
          local name = Fk:getCardById(id).name
          if room:getBanner("@"..name) then
            n = room:getBanner("@"..name) + 1
          else
            n = 1
          end
          room:setBanner("@"..name, n)
        end
      end
    elseif event == fk.TurnEnd then
      local dummy = Fk:cloneCard("br__jink")
      local n = 5
      if player:getMark("extra_scenario") > 0 then n = 8 end
      for _, id in ipairs(player:getPile("#scenario")) do
        local name = Fk:getCardById(id).name
        if room:getBanner("@"..name) and room:getBanner("@"..name) >= n then
          dummy:addSubcard(id)
        end
      end
      if #dummy.subcards > 0 then
        player.room:moveCardTo(dummy, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial and 
            Fk:getCardById(info.cardId):getMark("@@policy") ~= 0 then
              local name = Fk:getCardById(info.cardId).name
              room:setBanner("@"..name, 0)
            end
          end
        end
      end
    end
  end,
}

Fk:addSkill(policy_skills)

--毒计

local trap_skills = fk.CreateTriggerSkill{
  name = "#trap_skill",
  mute = true,
  priority = 2,
  events = {fk.TurnStart, fk.TurnEnd, fk.DamageInflicted, fk.EventPhaseStart, fk.EventPhaseEnd, fk.CardUseFinished, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return target == player and ld.hasPolicyorTrap(player, "mutiny")
    elseif event == fk.TurnEnd then
      return target == player and ld.hasPolicyorTrap(player, "eightdiagrams")  
    elseif event == fk.DamageInflicted then
      return target == player and ld.hasPolicyorTrap(player, "surround") and data.card and data.card.name == "br__slash"
    elseif event == fk.EventPhaseStart then
      return target == player and player.phase == Player.Play and ld.hasPolicyorTrap(player, "plague")
    elseif event == fk.EventPhaseEnd then
      return target == player and player.phase == Player.Play and ld.hasPolicyorTrap(player, "refugee")
    elseif event == fk.CardUseFinished then
      return target == player and ld.hasPolicyorTrap(player, "party_struggle") and data.card:getMark("@@policy") ~= 0
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id and move.extra_data and move.extra_data.baitbook then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      ld.invokePolicyorTrap(player, "mutiny")
      room:addPlayerMark(player, "free_instruction")
      room:useVirtualCard("br__slash", nil, player, player, "mutiny", true) 
    elseif event == fk.DamageInflicted then
      ld.invokePolicyorTrap(player, "surround")
      data.damage = data.damage + 1
    elseif event == fk.TurnEnd then
      if ld.hasPolicyorTrap(player, "eightdiagrams") then
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "eightdiagrams" end)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
        local mark = player:getTableMark("invalid_replace")
        table.removeOne(mark, id)
        room:setPlayerMark(player, "invalid_replace", mark)
      end
    elseif event == fk.EventPhaseStart or event == fk.EventPhaseEnd then
      if event == fk.EventPhaseStart then
        ld.invokePolicyorTrap(player, "plague")
      elseif event == fk.EventPhaseEnd then
        ld.invokePolicyorTrap(player, "refugee")
      end
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|heart,diamond",
      }
      room:judge(judge)
      local result = judge.card
      if result.color == Card.Black then
        ld.addinstruction(player, -2)
      end
    elseif event == fk.CardUseFinished then
      ld.invokePolicyorTrap(player, "party_struggle")
      room:sendLog{
        type = "#throwtrick",
        from = player.id,
        arg = data.card:toLogString(),
        toast = true,
      }
      room:moveCardTo(data.card, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      if ld.hasPolicyorTrap(player, "party_struggle") then
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "party_struggle" end)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
        local mark = player:getTableMark("invalid_replace")
        table.removeOne(mark, id)
        room:setPlayerMark(player, "invalid_replace", mark)
      end
    elseif event == fk.AfterCardsMove then
      ld.invokePolicyorTrap(player, "baitbook")
      local n = #player:getCardIds("he") + #player:getPile("#standby") + #player:getPile("#scenario&") + #table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@trap") == 0 end)
      n = math.min(n, 4)
      if n > 0 then
        local to_discard = {}
        if #player:getCardIds{Player.Hand} ~= 0 then table.insertIfNeed(to_discard, {"$Hand", player:getCardIds{Player.Hand}}) end
        if #player:getCardIds{Player.Equip} ~= 0 then table.insertIfNeed(to_discard, {"$Equip", player:getCardIds{Player.Equip}}) end
        if #player:getPile("#scenario&") ~= 0 then table.insertIfNeed(to_discard, {"#scenario&", player:getPile("#scenario&")}) end
        if #table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@trap") == 0 end) ~= 0 then
           table.insertIfNeed(to_discard, {"policy", table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id):getMark("@@trap") == 0 end)}) end
        if #player:getPile("#standby") ~= 0 then table.insertIfNeed(to_discard, {"#standby", player:getPile("#standby")}) end
        if #player:getPile("sixdragon") ~= 0 then table.insertIfNeed(to_discard, {"sixdragon", player:getPile("sixdragon")}) end
        local cards = room:askForCardsChosen(player, player, n, n, {
          card_data = to_discard
        }, self.name)
        if #cards > 0 then
          room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
        end
      end
    end
  end,

  refresh_events = {fk.Damaged, fk.Damage, fk.AfterCardUseDeclared, fk.BeforeCardsMove},
  can_refresh = function(self, event, target, player, data)
    if event == fk.Damaged then
      return target == player and ld.hasPolicyorTrap(player, "mutiny")
    elseif event == fk.Damage then
      return target == player and ld.hasPolicyorTrap(player, "surround") and data.card and data.card.name == "br__slash"
    elseif event == fk.AfterCardUseDeclared then
      return target == player and (data.card.name == "br__grain" or data.card.name == "br__analeptic")
    elseif event == fk.BeforeCardsMove then
      if ld.hasPolicyorTrap(player, "baitbook") then
        for _, move in ipairs(data) do
          if move.from and move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerSpecial and player:getPileNameOfId(info.cardId) == "#scenario" then
                return true
              end
            end
          end
        end      
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local mark = player:getTableMark("invalid_replace")
      local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "mutiny" end)[1]
      table.removeOne(mark, id)
      room:setPlayerMark(player, "invalid_replace", mark)
    elseif event == fk.Damage then
      local mark = player:getTableMark("invalid_replace")
      local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "surround" end)[1]
      table.removeOne(mark, id)
      room:setPlayerMark(player, "invalid_replace", mark)
    elseif event == fk.AfterCardUseDeclared then
      if data.card.name == "br__analeptic" and ld.hasPolicyorTrap(player, "plague") then
        local mark = player:getTableMark("invalid_replace")
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "plague" end)[1]
        table.removeOne(mark, id)
        room:setPlayerMark(player, "invalid_replace", mark)
      elseif data.card.name == "br__grain" and ld.hasPolicyorTrap(player, "refugee") then
        local mark = player:getTableMark("invalid_replace")
        local id = table.filter(player:getPile("#scenario"), function(id) return Fk:getCardById(id).name == "refugee" end)[1]
        table.removeOne(mark, id)
        room:setPlayerMark(player, "invalid_replace", mark)
      end
    elseif event == fk.BeforeCardsMove then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id then
          local ids = {}
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial and player:getPileNameOfId(info.cardId) == "#scenario" and
            Fk:getCardById(info.cardId).name == "baitbook" then
              table.insertIfNeed(ids, info.cardId)
            end
          end
          if #ids > 0 then
            move.extra_data = move.extra_data or {}
            move.extra_data.baitbook = ids
          end
        end
      end 
    end
  end,
}

Fk:addSkill(trap_skills)

Fk:loadTranslationTable{
  ["#policy_skill"] = "方针",
  ["@@emperor_hostage-turn"] = "<font color=\"#B87333\">挟天子</font>",
  ["#bj-give"] = "借荆州：请交给%dest两张牌",

  ["#trap_skill"] = "毒计",
}


return extension